﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MovieInfoView
{
    /// <summary>
    /// Interaction logic for EditBox.xaml
    /// </summary>
    public partial class EditBox : TextBox
    {
        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            base.OnMouseUp(e);

            //the user has clicked on the control, they want to edit it
            this.Focusable = true;
            this.Cursor = Cursors.IBeam;
            this.Focus();
            this.SelectAll();
        }

        public void _loseFocus()
        {
            this.Focusable = false;
            this.Select(0, 0);
            this.Cursor = Cursors.Hand;
        }

        protected override void OnKeyUp(KeyEventArgs e)
        {
            if (e.ImeProcessedKey != Key.Enter)
                base.OnKeyUp(e);
            else
            {
                this.Focusable = false;
                this.Select(0, 0);
                this.Cursor = Cursors.Hand;
            }
        }
    }
}
